package com.auxgroup.hr.front.site.co.hireperson;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.BaseRetCode;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCHireTactPer;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.hireperson.HireTactPerService;
import com.auxgroup.hr.front.site.co.BaseCO;

/**
 * 紧急联系人CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/hireTactPer")
public class HireTactPerCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(HireTactPerCO.class);

	@Autowired
	public HireTactPerService hireTactPerService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 获取紧急联系人
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String rsHireId) {
		logger.info("getHireTactPer param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_REQUEST_PARAM_NULL.getRetCode(),"入职人员ID不能为空");
		}
		PsCHireTactPer hireTactPer = hireTactPerService.getHireTactPer(rsHireId);
		return buildRespone(hireTactPer);
	}
	
	/**
	 * 保存紧急联系人
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(PsCHireTactPer hireTactPer) {
		logger.info("saveHireTactPer param= {}", hireTactPer);
		if(StringUtils.isBlank(hireTactPer.getRsHireId())){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		PsCHireTactPer nowTactper = hireTactPerService.getHireTactPer(hireTactPer.getRsHireId());
		if(nowTactper!=null){
			objectMapper.map(hireTactPer, nowTactper,"notCopyNull_hireTactPer");
			hireTactPer = hireTactPerService.save(nowTactper);
		}else{
			hireTactPer = hireTactPerService.save(hireTactPer);
		}
		if(hireTactPer.getRsHireId()!=null){
			return buildRespone(true);
		}
		return buildRespone(false);
		
	}
	
	/**
	 * 删除紧急联系人
	 * @param hireId
	 * @return
	 */
	@PostMapping(value = "/del")
	public BaseResponseVO del(String rsHireId) {
		logger.info("delHireTactPer param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		Boolean isdel = hireTactPerService.delete(rsHireId);
		return buildRespone(isdel);
	}
	
	/**
	 * 获取全部紧急联系人
	 * @param rsHireId
	 * @return
	 */
	@GetMapping(value = "/getAll")
	public BaseResponseVO getAll(String rsHireId){
		logger.info("getHireTactPer param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		List<PsCHireTactPer> list = hireTactPerService.getAll(rsHireId);
		return buildRespone(list);
	}
	
	

}
